package fr.excilys.gwt.events.client.component;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;

import fr.excilys.gwt.events.client.event.AddPhoneNumberEvent;
import fr.excilys.gwt.events.client.event.AddPhoneNumberHandler;
import fr.excilys.gwt.events.client.event.ExcilysEventBus;

public class PhoneNumberList extends Composite {

	private final ExcilysEventBus eventBus = ExcilysEventBus.INSTANCE;

	public PhoneNumberList() {
		final ListBox listBox = new ListBox(true);
		listBox.setVisibleItemCount(10);
		listBox.setWidth("250px");
		initWidget(listBox);

		eventBus.addHandler(AddPhoneNumberEvent.getType(),
				new AddPhoneNumberHandler() {
					@Override
					public void onAddPhoneNumber(AddPhoneNumberEvent event) {
						listBox.addItem(event.getPhoneNumber());
					}
				});
	}
}
